/**
 * 获取后端数据
 */
const apiUtil = require("../utils/apiUtil")
const dateUtil = require("../utils/dateUtil")
const resourceApi = {
    list(){
        return new Promise((resolve,reject)=>{
            apiUtil.get("/file/list",{type: "学习资料"}).then(resp=>{
                if(resp.code == 200){
                    resp.data.forEach(item => {
                        if(!String(item.cover).startsWith("http")){
                            item.cover=apiUtil.defaultApiPath+item.cover
                        }
                        item.created = dateUtil.dateFormat("YY-mm-dd",new Date(item.created))
                    });
                    resolve(resp.data)
                }else{
                    reject(resp.message)
                }
            }).catch(err=>{
                reject(err)
            })
        })
    }
}
module.exports = resourceApi;